﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Library
{
    public static class Helper
    {
        #region Const

        public const string ENTITY_NAME = "LabManagerEntities";
        public const string LANGUAGE = "Language";
        public const string EMPTY_STRING = "<empty>";
        public const string DATE_FORMAT = "dd.MM.yyyy";
        public const string STANDARD_PW = "042244095024200188249166113165075142084172075233"; // 1234

        #endregion

        #region Helper

        public static void DisableGrid(DataGridView dgMain, BindingNavigator bnNavi, TextBox tbFilter)
        {
            dgMain.ReadOnly = true;
            dgMain.Enabled = false;
            dgMain.ClearSelection();
            dgMain.ForeColor = Color.Gray;
            dgMain.BackgroundColor = Color.LightGray;

            tbFilter.Enabled = false;
            bnNavi.Enabled = false;
        }

        public static void EnableGrid(DataGridView dgMain, BindingNavigator bnNavi, TextBox tbFilter)
        {
            dgMain.ReadOnly = false;
            dgMain.Enabled = true;
            dgMain.ForeColor = Color.Black;
            dgMain.BackgroundColor = Color.White;

            tbFilter.Enabled = true;
            bnNavi.Enabled = true;  
        }

        public static string Reverse(string input)
        {
            return new string(input.ToCharArray().Reverse().ToArray());
        }

        public static string GetSHA1(string input)
        {
            //Umwandlung des Eingastring in den SHA1 Hash
            System.Security.Cryptography.SHA1 sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            byte[] textToHash = Encoding.Default.GetBytes(input);
            byte[] result = sha1.ComputeHash(textToHash);

            //SHA1 Hash in String konvertieren
            System.Text.StringBuilder s = new System.Text.StringBuilder();
            foreach (byte b in result)
            {
                s.Append(b.ToString("x2").ToLower());
            }

            return s.ToString();
        }

        #endregion
    }
}
